Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>PATCH (HTTP)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/PATCH_(HTTP)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-PATCH_HTTP rootpage-PATCH_HTTP skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">PATCH (HTTP)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" ยท ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}


/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1246091330">
/* start https://en.wikipedia.org/ */


.mw-parser-output .sidebar{width:22em;float:right;clear:right;margin:0.5em 0 1em 1em;background:var(--background-color-neutral-subtle,#f8f9fa);border:1px solid var(--border-color-base,#a2a9b1);padding:0.2em;text-align:center;line-height:1.4em;font-size:88%;border-collapse:collapse;display:table}body.skin-minerva .mw-parser-output .sidebar{display:table!important;float:right!important;margin:0.5em 0 1em 1em!important}.mw-parser-output .sidebar-subgroup{width:100%;margin:0;border-spacing:0}.mw-parser-output .sidebar-left{float:left;clear:left;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-none{float:none;clear:both;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-outer-title{padding:0 0.4em 0.2em;font-size:125%;line-height:1.2em;font-weight:bold}.mw-parser-output .sidebar-top-image{padding:0.4em}.mw-parser-output .sidebar-top-caption,.mw-parser-output .sidebar-pretitle-with-top-image,.mw-parser-output .sidebar-caption{padding:0.2em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-pretitle{padding:0.4em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-title,.mw-parser-output .sidebar-title-with-pretitle{padding:0.2em 0.8em;font-size:145%;line-height:1.2em}.mw-parser-output .sidebar-title-with-pretitle{padding:0.1em 0.4em}.mw-parser-output .sidebar-image{padding:0.2em 0.4em 0.4em}.mw-parser-output .sidebar-heading{padding:0.1em 0.4em}.mw-parser-output .sidebar-content{padding:0 0.5em 0.4em}.mw-parser-output .sidebar-content-with-subgroup{padding:0.1em 0.4em 0.2em}.mw-parser-output .sidebar-above,.mw-parser-output .sidebar-below{padding:0.3em 0.8em;font-weight:bold}.mw-parser-output .sidebar-collapse .sidebar-above,.mw-parser-output .sidebar-collapse .sidebar-below{border-top:1px solid #aaa;border-bottom:1px solid #aaa}.mw-parser-output .sidebar-navbar{text-align:right;font-size:115%;padding:0 0.4em 0.4em}.mw-parser-output .sidebar-list-title{padding:0 0.4em;text-align:left;font-weight:bold;line-height:1.6em;font-size:105%}.mw-parser-output .sidebar-list-title-c{padding:0 0.4em;text-align:center;margin:0 3.3em}@media(max-width:640px){body.mediawiki .mw-parser-output .sidebar{width:100%!important;clear:both;float:none!important;margin-left:0!important;margin-right:0!important}}body.skin--responsive .mw-parser-output .sidebar a>img{max-width:none!important}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media print{body.ns-0 .mw-parser-output .sidebar{display:none!important}}


/* end https://en.wikipedia.org/ */
</style><table class="sidebar nomobile nowraplinks hlist"><tbody><tr><th class="sidebar-title"><a href="HTTP" title="HTTP">HTTP</a></th></tr><tr><td class="sidebar-image"><span typeof="mw:File"></span></td></tr><tr><td class="sidebar-content">
<ul><li><a href="HTTP_persistent_connection" title="HTTP persistent connection">Persistence</a></li>
<li><a href="HTTP_compression" title="HTTP compression">Compression</a></li>
<li><a href="HTTPS" title="HTTPS">HTTPS</a></li>
<li><a href="QUIC" title="QUIC">QUIC</a></li></ul></td>
</tr><tr><th class="sidebar-heading">
<a href="HTTP#Request_methods" title="HTTP">Request methods</a></th></tr><tr><td class="sidebar-content">
<ul><li><a href="HTTP#Request_methods" title="HTTP">OPTIONS</a></li>
<li><a href="HTTP#Request_methods" title="HTTP">GET</a></li>
<li><a href="HTTP#Request_methods" title="HTTP">HEAD</a></li>
<li><a href="POST_(HTTP)" title="POST (HTTP)">POST</a></li>
<li><a href="HTTP#Request_methods" title="HTTP">PUT</a></li>
<li><a href="HTTP#Request_methods" title="HTTP">DELETE</a></li>
<li><a href="HTTP#Request_methods" title="HTTP">TRACE</a></li>
<li><a href="HTTP#Request_methods" title="HTTP">CONNECT</a></li>
</ul></td>
</tr><tr><th class="sidebar-heading">
<a href="List_of_HTTP_header_fields" title="List of HTTP header fields">Header fields</a></th></tr><tr><td class="sidebar-content">
<ul><li><a href="HTTP_cookie" title="HTTP cookie">Cookie</a></li>
<li><a href="HTTP_ETag" title="HTTP ETag">ETag</a></li>
<li><a href="HTTP_location" title="HTTP location">Location</a></li>
<li><a href="HTTP_referer" title="HTTP referer">HTTP referer</a></li>
<li><a href="Do_Not_Track" title="Do Not Track">DNT</a></li>
<li><a href="X-Forwarded-For" title="X-Forwarded-For">X-Forwarded-For</a></li></ul></td>
</tr><tr><th class="sidebar-heading">
<a href="List_of_HTTP_status_codes" title="List of HTTP status codes">Response status codes</a></th></tr><tr><td class="sidebar-content">
<ul><li><a href="HTTP_301" title="HTTP 301">301 Moved Permanently</a></li>
<li><a href="HTTP_302" title="HTTP 302">302 Found</a></li>
<li><a href="HTTP_303" title="HTTP 303">303 See Other</a></li>
<li><a href="HTTP_403" title="HTTP 403">403 Forbidden</a></li>
<li><a href="HTTP_404" title="HTTP 404">404 Not Found</a></li>
<li><a href="HTTP_451" title="HTTP 451">451 Unavailable for Legal Reasons</a></li></ul></td>
</tr><tr><th class="sidebar-heading">
Security access control methods</th></tr><tr><td class="sidebar-content">
<ul><li><a href="Basic_access_authentication" title="Basic access authentication">Basic access authentication</a></li>
<li><a href="Digest_access_authentication" title="Digest access authentication">Digest access authentication</a></li></ul></td>
</tr><tr><th class="sidebar-heading">
Security vulnerabilities</th></tr><tr><td class="sidebar-content">
<ul><li><a href="HTTP_header_injection" title="HTTP header injection">HTTP header injection</a></li>
<li><a href="HTTP_request_smuggling" title="HTTP request smuggling">HTTP request smuggling</a></li>
<li><a href="HTTP_response_splitting" title="HTTP response splitting">HTTP response splitting</a></li>
<li><a href="HTTP_parameter_pollution" title="HTTP parameter pollution">HTTP parameter pollution</a></li></ul></td>
</tr><tr><td class="sidebar-navbar"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */


.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}


/* end https://en.wikipedia.org/ */
</style></td></tr></tbody></table>
<p>In computing, the <b>PATCH</b> method is a <a href="Request-response" class="mw-redirect" title="Request-response">request</a> method in <a href="Hypertext_Transfer_Protocol" class="mw-redirect" title="Hypertext Transfer Protocol">HTTP</a> for making partial changes to an existing resource.<sup id="cite_ref-RFC5789_1-0" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> The PATCH method provides an entity containing a list of changes to be applied to the resource requested using the HTTP <a href="Uniform_Resource_Identifier" title="Uniform Resource Identifier">Uniform Resource Identifier</a> (URI).<sup id="cite_ref-RFC5789_1-1" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> The list of changes are supplied in the form of a PATCH document.<sup id="cite_ref-RFC5789_1-2" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> If the requested resource does not exist then the <a href="Server_(computing)" title="Server (computing)">server</a> may create the resource depending on the PATCH document <a href="Media_type" title="Media type">media type</a> and permissions.<sup id="cite_ref-RFC5789_1-3" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> The changes described in the PATCH document must be semantically well defined but can have a different <a href="Media_type" title="Media type">media type</a> than the resource being patched.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> Languages such as <a href="XML" title="XML">XML</a> or <a href="JSON" title="JSON">JSON</a> can be used in describing the changes in the PATCH document.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="History_of_PATCH">History of PATCH</h2></div>
<p>As per the semantics defined in the <a href="Hypertext_Transfer_Protocol" class="mw-redirect" title="Hypertext Transfer Protocol">HTTP</a> protocol, the <a href="HTTP_GET" class="mw-redirect" title="HTTP GET">GET</a>, <a href="HTTP_PUT" class="mw-redirect" title="HTTP PUT">PUT</a>, and <a href="HTTP_POST" class="mw-redirect" title="HTTP POST">POST</a> methods need to use a full representation of the resource. The PUT method which can be used for resource creation or replacement is <a href="Idempotent" class="mw-redirect" title="Idempotent">idempotent</a> and can be used only for full updates. The edit forms used in conventional <a href="Ruby_on_Rails" title="Ruby on Rails">Ruby on Rails</a> application need to create new resources by applying partial updates to a parent resource. Due to this requirement, the PATCH method was added to the HTTP protocol in 2010.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-History_of_PATCH_4-0" class="reference"><a href="#cite_note-History_of_PATCH-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="PUT_vs_PATCH_vs_POST">PUT vs PATCH vs POST</h2></div>
<p><a href="HTTP" title="HTTP">HTTP</a> is the foundation of data communication for the <a href="World_Wide_Web" title="World Wide Web">World Wide Web</a>. It is a <a href="Request-response" class="mw-redirect" title="Request-response">request-response</a> protocol which helps users communicate with the server to perform <a href="CRUD" class="mw-redirect" title="CRUD">CRUD</a> operations. HTTP defines a number of request methods such as <a href="HTTP_PUT" class="mw-redirect" title="HTTP PUT">PUT</a>, <a href="HTTP_POST" class="mw-redirect" title="HTTP POST">POST</a> and PATCH to create or update resources.<sup id="cite_ref-RFC2616_5-0" class="reference"><a href="#cite_note-RFC2616-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p><p>The main difference between the PUT and PATCH method is that the PUT method uses the request <a href="URI" class="mw-redirect" title="URI">URI</a> to supply a modified version of the requested resource which replaces the original version of the resource, whereas the PATCH method supplies a set of instructions to modify the resource. If the PATCH document is larger than the size of the new version of the resource sent by the <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">PUT</a> method then the <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">PUT</a> method is preferred.<sup id="cite_ref-RFC5789_1-4" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>The POST method can be used for sending partial updates to a resource. The main difference between the POST and PATCH methods is that the POST method can be used only when it is written to support the applications or the applications support its semantics whereas the PATCH method can be used in a generic way and does not require application support. If the outcome of using the PATCH method is not known then the POST method is preferred.<sup id="cite_ref-RFC5789_1-5" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Patching_resources">Patching resources</h2></div>
<p>The PATCH method is <a href="Atomicity_(database_systems)" title="Atomicity (database systems)">atomic</a>.<sup id="cite_ref-RFC5789_1-6" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> Either all the changes specified by the PATCH method are applied or none of the changes are applied by the server.<sup id="cite_ref-RFC5789_1-7" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> There are many ways of checking whether a patch was applied successfully. For example, the <a href="Diff_utility" class="mw-redirect" title="Diff utility">'diff' utility</a> can be applied to the older version and newer version of a file to find the differences between them.<sup id="cite_ref-RFC5789_1-8" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>A cached PATCH response is considered stale. It can only be used for the GET and HEAD requests that may follow the PATCH request.<sup id="cite_ref-RFC5789_1-9" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>The entity headers in the PATCH document are only applicable to the PATCH document and cannot be applied to the requested resource.<sup id="cite_ref-RFC5789_1-10" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>There is no standard format for the PATCH document and it is different for different types of resources. The server has to check whether the PATCH document received is appropriate for the requested resource.<sup id="cite_ref-RFC5789_1-11" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>A <a href="JSON_Patch" title="JSON Patch">JSON Patch</a> document would look like
</p>
<div class="mw-highlight mw-highlight-lang-json mw-content-ltr" dir="ltr"><pre><span class="p">[</span>
<span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nt">"op"</span><span class="p">:</span><span class="w"> </span><span class="s2">"add"</span><span class="p">,</span><span class="w"> </span><span class="nt">"path"</span><span class="p">:</span><span class="w"> </span><span class="s2">"/count"</span><span class="p">,</span><span class="w"> </span><span class="nt">"value"</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">}</span>
<span class="p">]</span>
</pre></div>
<p>"op" represents the operation performed on the resource. "path" represents the resource being modified. "value" represents the amount being added to the existing resource.<sup id="cite_ref-RFCJSONPATCH_7-0" class="reference"><a href="#cite_note-RFCJSONPATCH-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> Before applying the changes in the PATCH document, the server has to check whether the PATCH document received is appropriate for the requested resource. If the PATCH request succeeds then it returns a <b>204</b> response.<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup>
</p><p>A <b>XML</b> PATCH document would look like
</p>
<div class="mw-highlight mw-highlight-lang-xml mw-content-ltr" dir="ltr"><pre><span class="nt">&lt;add</span><span class="w"> </span><span class="na">sel=</span><span class="s">"doc/user[@email='xyz@abc.com']"</span><span class="w"> </span><span class="na">type=</span><span class="s">"@address"</span><span class="nt">&gt;</span>
ABC<span class="w"> </span>Road
<span class="nt">&lt;/add&gt;</span>
</pre></div>
<p>The element &lt;user&gt; is located using the 'email' attribute. A new attribute 'address' with the value "ABC Road" is added to the &lt;user&gt; element.<sup id="cite_ref-XML_RFC_9-0" class="reference"><a href="#cite_note-XML_RFC-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Example">Example</h2></div>
<p>A simple PATCH request example
</p>
<div class="">
<pre> <code class="mw-highlight mw-highlight-lang-http mw-content-ltr" style="background:none; border:none; color:inherit; padding: 0px 0px;" dir="ltr"><span class="nf">PATCH</span> <span class="nn">/example.txt</span> <span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span></code>
Host: www.example.com
Content-Type: application/example
<a rel="nofollow" class="external text" href="https://msdn.microsoft.com/en-us/library/dd541480.aspx">If-Match</a>: "c0b42b66e"
Content-Length: 120
[<i>Changes</i>: the patch document containing all the changes that need to be made on the resource example.txt]
</pre>
</div>
<p>Successful PATCH response to existing text file:
</p>
<pre> <code class="mw-highlight mw-highlight-lang-http mw-content-ltr" style="background:none; border:none; color:inherit; padding: 0px 0px;" dir="ltr"><span class="kr">HTTP</span><span class="o">/</span><span class="m">1.1</span> <span class="m">204</span> <span class="ne">No Content</span></code>
Content-Location: /example.txt
<a href="HTTP_ETag" title="HTTP ETag">ETag</a>: "dd541480"
</pre>
<p>The response <i>204</i> means that the request was processed successfully.<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Trade-offs_between_PUT_and_PATCH">Trade-offs between PUT and PATCH</h2></div>
<p>Using the <a href="PUT_(HTTP)" class="mw-redirect" title="PUT (HTTP)">PUT</a> method consumes more bandwidth as compared to the PATCH method when only a few changes need to be applied to a resource. But when the PATCH method is used, it usually involves fetching the resource from the server, comparing the original and new files, creating and sending a diff file. On the server side, the server has to read the diff file and make the modifications. This involves a lot of overhead compared to the PUT method.<sup id="cite_ref-51elliot_11-0" class="reference"><a href="#cite_note-51elliot-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>
On the other hand, the <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">PUT</a> method requires a <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">GET</a> to be performed before the <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">PUT</a> and it is difficult to ensure that the resource is not modified between the <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">GET</a> and <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">PUT</a> requests.
</p>
<div class="mw-heading mw-heading2"><h2 id="Caution">Caution</h2></div>
<p>The PATCH method is not "safe" in the sense of RFC 2616: it may modify resources, not necessarily limited to those mentioned in the <a href="URI" class="mw-redirect" title="URI">URI</a>.<sup id="cite_ref-RFC5789_1-12" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p><p>The PATCH method is not <a href="Idempotence" title="Idempotence">idempotent</a>. It can be made <a href="Idempotence" title="Idempotence">idempotent</a> by using a conditional request.<sup id="cite_ref-RFC5789_1-13" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> When a client makes a conditional request to a resource, the request succeeds only if the resource has not been updated since the client last accessed that resource. This also helps in preventing corruption of the resource since some updates to a resource can only be performed starting from a certain base point.<sup id="cite_ref-RFC5789_1-14" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Error_handling">Error handling</h2></div>
<p>A PATCH request can fail if any of the following errors occur:
</p>
<div class="mw-heading mw-heading3"><h3 id="Malformed_patch_document">Malformed patch document</h3></div>
<p>The server returns a 400 (Bad request) response if the PATCH document is not formatted as required.<sup id="cite_ref-RFC5789_1-15" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Unsupported_patch_document">Unsupported patch document</h3></div>
<p>The server returns a 415 (Unsupported <a href="Media_type" title="Media type">Media Type</a>) response with an <a href="List_of_HTTP_header_fields" title="List of HTTP header fields">Accept-Patch response header</a> containing supported <a href="Media_type" title="Media type">media types</a> when the client sends a patch document in a format not implemented by the server. This informs the client that the PATCH document sent by the client cannot be applied to the requested resource.<sup id="cite_ref-RFC5789_1-16" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Unprocessable_request">Unprocessable request</h3></div>
<p>The server returns a 422 (Unprocessable Entity) response when the server understands the PATCH document but is unable to modify the requested resource either because it causes the resource to become invalid or it results in some other error state.<sup id="cite_ref-RFC5789_1-17" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Resource_not_found">Resource not found</h3></div>
<p>The server returns a 404 (Not Found) response when the PATCH document cannot be applied to a non-existent resource.<sup id="cite_ref-RFC5789_1-18" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Conflicting_state">Conflicting state</h3></div>
<p>The server returns a 409 (Conflict) response when the server cannot apply a patch for the current state of the resource.<sup id="cite_ref-RFC5789_1-19" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Conflicting_modification">Conflicting modification</h3></div>
<p>The server returns a 412 (Precondition Failed) response when the precondition supplied by the client using the <a rel="nofollow" class="external text" href="https://msdn.microsoft.com/en-us/library/dd541480.aspx">If-Match</a> or If-Unmodified-Since header fails. If no precondition is supplied and there is a conflicting modification then the server returns a 409 (Conflict) response.<sup id="cite_ref-RFC5789_1-20" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Concurrent_modification">Concurrent modification</h3></div>
<p>The server returns a 409 (Conflict) response if the PATCH requests to a certain resource need to be applied in a certain order and the server is not able to handle concurrent PATCH requests.<sup id="cite_ref-RFC5789_1-21" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Security_considerations">Security considerations</h2></div>
<p>The PATCH request needs to use mechanisms such as conditional requests using <a href="HTTP_ETag" title="HTTP ETag">Etags</a> and the <a rel="nofollow" class="external text" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match">If-Match</a> request header to ensure that data is not corrupted while patching.<sup id="cite_ref-RFC5789_1-22" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> In case of a failure of a PATCH request or failure of the channel or a timeout, the client can use a <a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">GET</a> request to check the state of the resource.<sup id="cite_ref-RFC5789_1-23" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> The server has to ensure that malicious clients do not use the PATCH method for consuming excessive server resources.<sup id="cite_ref-RFC5789_1-24" class="reference"><a href="#cite_note-RFC5789-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-RFC5789-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-RFC5789_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-RFC5789_1-1"><sup><i><b>b</b></i></sup></a> <a href="#cite_ref-RFC5789_1-2"><sup><i><b>c</b></i></sup></a> <a href="#cite_ref-RFC5789_1-3"><sup><i><b>d</b></i></sup></a> <a href="#cite_ref-RFC5789_1-4"><sup><i><b>e</b></i></sup></a> <a href="#cite_ref-RFC5789_1-5"><sup><i><b>f</b></i></sup></a> <a href="#cite_ref-RFC5789_1-6"><sup><i><b>g</b></i></sup></a> <a href="#cite_ref-RFC5789_1-7"><sup><i><b>h</b></i></sup></a> <a href="#cite_ref-RFC5789_1-8"><sup><i><b>i</b></i></sup></a> <a href="#cite_ref-RFC5789_1-9"><sup><i><b>j</b></i></sup></a> <a href="#cite_ref-RFC5789_1-10"><sup><i><b>k</b></i></sup></a> <a href="#cite_ref-RFC5789_1-11"><sup><i><b>l</b></i></sup></a> <a href="#cite_ref-RFC5789_1-12"><sup><i><b>m</b></i></sup></a> <a href="#cite_ref-RFC5789_1-13"><sup><i><b>n</b></i></sup></a> <a href="#cite_ref-RFC5789_1-14"><sup><i><b>o</b></i></sup></a> <a href="#cite_ref-RFC5789_1-15"><sup><i><b>p</b></i></sup></a> <a href="#cite_ref-RFC5789_1-16"><sup><i><b>q</b></i></sup></a> <a href="#cite_ref-RFC5789_1-17"><sup><i><b>r</b></i></sup></a> <a href="#cite_ref-RFC5789_1-18"><sup><i><b>s</b></i></sup></a> <a href="#cite_ref-RFC5789_1-19"><sup><i><b>t</b></i></sup></a> <a href="#cite_ref-RFC5789_1-20"><sup><i><b>u</b></i></sup></a> <a href="#cite_ref-RFC5789_1-21"><sup><i><b>v</b></i></sup></a> <a href="#cite_ref-RFC5789_1-22"><sup><i><b>w</b></i></sup></a> <a href="#cite_ref-RFC5789_1-23"><sup><i><b>x</b></i></sup></a> <a href="#cite_ref-RFC5789_1-24"><sup><i><b>y</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFDusseaultSnell2010" class="citation journal cs1">Dusseault, L.; Snell, J. (2010). <span class="id-lock-subscription" title="Paid subscription required"><a rel="nofollow" class="external text" href="http://tools.ietf.org/html/rfc5789">"PATCH Method for HTTP"</a></span>. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.17487%2FRFC5789">10.17487/RFC5789</a>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:42062521">42062521</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2015-09-12</span></span>.</cite> <span class="cs1-visible-error citation-comment"><code class="cs1-code">{{cite journal}}</code>: </span><span class="cs1-visible-error citation-comment">Cite journal requires <code class="cs1-code">|journal=</code> (help)</span></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/">"Don't Patch Like An Idiot"</a>. <i>Don't Patch Like An Idiot</i>. 14 February 2014<span class="reference-accessdate">. Retrieved <span class="nowrap">16 September</span> 2015</span>.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><a href="https://datatracker.ietf.org/doc/html/rfc5789" class="extiw external" title="rfc:5789">RFC 5789</a></span>
</li>
<li id="cite_note-History_of_PATCH-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-History_of_PATCH_4-0">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://weblog.rubyonrails.org/2012/2/26/edge-rails-patch-is-the-new-primary-http-method-for-updates/">"History of PATCH"</a>. <i>weblog.rubyonrails.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">25 September</span> 2015</span>.</cite></span>
</li>
<li id="cite_note-RFC2616-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-RFC2616_5-0">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.ietf.org/rfc/rfc2616.txt">"Hypertext Transfer Protocol -- HTTP/1.1"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">13 September</span> 2015</span>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.mnot.net/blog/2012/09/05/patch">"Why PATCH is Good for Your HTTP API"</a>. <i>Why PATCH is Good for Your HTTP API</i><span class="reference-accessdate">. Retrieved <span class="nowrap">16 September</span> 2015</span>.</cite></span>
</li>
<li id="cite_note-RFCJSONPATCH-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-RFCJSONPATCH_7-0">^</a></b></span> <span class="reference-text"><cite class="citation news cs1"><a rel="nofollow" class="external text" href="https://tools.ietf.org/html/draft-ietf-appsawg-json-patch-08">"JSON Patch - draft-ietf-appsawg-json-patch-08"</a>. <i>Ietf Datatracker</i><span class="reference-accessdate">. Retrieved <span class="nowrap">13 September</span> 2015</span>.</cite></span>
</li>
<li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH">"PATCH"</a>. <i>MDN Web Docs</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-10-11</span></span>.</cite></span>
</li>
<li id="cite_note-XML_RFC-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-XML_RFC_9-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFUrpalainen2008" class="citation journal cs1">Urpalainen, J. (2008). <span class="id-lock-subscription" title="Paid subscription required"><a rel="nofollow" class="external text" href="http://tools.ietf.org/html/rfc5261">"XML RFC"</a></span>. <i>tools.ietf.org</i>. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.17487%2FRFC5261">10.17487/RFC5261</a><span class="reference-accessdate">. Retrieved <span class="nowrap">25 September</span> 2015</span>.</cite></span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH">"PATCH"</a>. <i>MDN Web Docs</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2018-10-12</span></span>.</cite></span>
</li>
<li id="cite_note-51elliot-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-51elliot_11-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFDarren2014" class="citation web cs1">Darren (7 May 2014). <a rel="nofollow" class="external text" href="http://51elliot.blogspot.com/2014/05/rest-api-best-practices-3-partial.html">"REST API Best Practices 3: Partial Updates - PATCH vs PUT"</a>. <i>www.blogger.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">13 September</span> 2015</span>.</cite></span>
</li>
</ol></div></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-05-25" href="https://en.wikipedia.org/wiki/?title=PATCH_(HTTP)&amp;oldid=1292181723">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>